//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.purvar.boot.api.service.impl;

import com.purvar.boot.api.mapper.MySQLGeneratorMapper;
import com.purvar.boot.api.service.IMySQLGeneratorService;
import com.purvar.boot.comm.api.vo.TableEntity;
import com.purvar.boot.comm.util.GenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
@Configuration
@PropertySource({"classpath:generator.properties"})
public class MySQLGeneratorServiceImpl implements IMySQLGeneratorService {
    @Autowired
    private MySQLGeneratorMapper mySQLGeneratorMapper;
    @Autowired
    private Environment env;

    public MySQLGeneratorServiceImpl() {
    }

    public TableEntity getTableEntity(String tableName) {
        return GenUtils.generatorCode(this.env, this.queryTable(tableName), this.queryColumns(tableName));
    }

    public TableEntity getdataBaseTableEntity(String tableName) {
        return GenUtils.generatorDataBaseCode(this.env, this.queryTable(tableName), this.queryColumns(tableName));
    }

    public List<TableEntity> listTableEntity(String tableNameParam) {
        List list = new ArrayList();
        List<Map<String, Object>> tableNameList = this.queryList(tableNameParam);

        for (int i = 0; i < tableNameList.size(); ++i) {
            Map<String, Object> map = (Map) tableNameList.get(i);
            String tableName = map.get("tableName").toString();
            TableEntity tableEntity = GenUtils.generatorCode(this.env, this.queryTable(tableName), (List) null);
            list.add(tableEntity);
        }

        return list;
    }

    private List<Map<String, Object>> queryList(String map) {
        List<Map<String, Object>> list = this.mySQLGeneratorMapper.queryList(map);
        return list;
    }

    private Map<String, String> queryTable(String tableName) {
        Map<String, String> map = this.mySQLGeneratorMapper.queryTable(tableName);
        return map;
    }

    private List<Map<String, Object>> queryColumns(String tableName) {
        List<Map<String, Object>> list = this.mySQLGeneratorMapper.queryColumns(tableName);
        return list;
    }
}
